package com.item.controller;

import com.item.mq.config.KeyPairConfig;
import com.item.util.EncryptionUtil;
import com.item.util.HttpClientUtil;
import com.item.util.JSONUtil;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试接口的加密传输
 * @author zhang-rongyao
 * @version V1.0
 * @Package com.item.model
 * @date 2021/7/27 10:22
 */
@SpringBootTest
public class EEE {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    KeyPairConfig keyPairConfig;

    @Test
    public void sendInfo() throws Exception {
        //甲方需要传输给乙方的文本
        String str="aattaggcctegthththfef/aat.mp4";

        Map map=new HashMap<String, String>();
        map.put("data",str);

        //aaa乙方  zhx甲方
        // 甲方用乙方公钥加密data,用自己的私钥做数据签名
        Map sdf = EncryptionUtil.cipherData(map, keyPairConfig.getZhxPrivateKey(), keyPairConfig.getAaaPublicKey());

        String post = HttpClientUtil.doPostJson("http://localhost:8881/tw/mq/send", JSONUtil.toJson(sdf));
        System.out.println("==============="+post);

    }

    @Test
    public void sendInfo2() throws Exception {
        //甲方需要传输给乙方的文本
        String str="aattaggcctegthththfef/aat.mp4";

        Map map=new HashMap<String, String>();
        map.put("data",str);

        String post = HttpClientUtil.doPostJson("http://localhost:8881/tw/mq/send2", JSONUtil.toJson(map));
        System.out.println("==============="+post);

    }

}
